<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* Mapv (https://github.com/huiyan-fe/mapv)
*********************************************************************-->
<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <script type="text/javascript" include="mapv" src="../../dist/ol/include-ol.js"></script>
    <title data-i18n="resources.title_mapvQianxiTime"></title>
    <style>
        .ol-popup {
            position: absolute;
            background-color: white;
            -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            padding: 15px;
            border-radius: 10px;
            border: 1px solid #cccccc;
            bottom: 12px;
            left: -50px;
            min-width: 280px;
            font-size: 8pt;
        }

        .ol-popup:after, .ol-popup:before {
            top: 100%;
            border: solid transparent;
            content: " ";
            height: 0;
            width: 0;
            position: absolute;
            pointer-events: none;
        }

        .ol-popup:after {
            border-top-color: white;
            border-width: 10px;
            left: 48px;
            margin-left: -10px;
        }

        .ol-popup:before {
            border-top-color: #cccccc;
            border-width: 11px;
            left: 48px;
            margin-left: -11px;
        }

        .ol-popup-closer {
            text-decoration: none;
            position: absolute;
            top: 2px;
            right: 8px;
        }

        .ol-popup-closer:after {
            content: "✖";
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<div id="popup" class="ol-popup">
    <a href="#" id="popup-closer" class="ol-popup-closer"></a>
    <div id="popup-content" data-i18n="resources.text_iClient"></div>
</div>
<script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
<script type="text/javascript">
    var container = document.getElementById('popup');
    var closer = document.getElementById('popup-closer');
    var overlay = new ol.Overlay(({
        element: container,
        autoPan: true,
        autoPanAnimation: {
            duration: 250
        }
    }));
    closer.onclick = function () {
        overlay.setPosition(undefined);
        closer.blur();
        return false;
    };
    var map = new ol.Map({
        target: 'map',
        // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
        controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
            .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
        overlays: [overlay],
        view: new ol.View({
            center: ol.proj.transform([105.403119, 38.028658], 'EPSG:4326', 'EPSG:3857'),
            zoom: 4,
            projection: 'EPSG:3857',
            multiWorld: true
        })
    });

    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var url = host + "/iserver/services/map-china/rest/maps/ChinaDark";
    map.addLayer(new ol.layer.Tile({
        source: new ol.source.TileSuperMapRest({
            url: url,
            attributions: "Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a>"
        })
    }));
    overlay.setPosition(map.getView().getCenter());

    var data = [];
    var timeData = [];

    function curive(fromPoint, endPoint, n) {
        var delLng = (endPoint.lng - fromPoint.lng) / n;
        var delLat = (endPoint.lat - fromPoint.lat) / n;

        for (var i = 0; i < n; i++) {
            var pointNLng = fromPoint.lng + delLng * i;
            var pointNLat = fromPoint.lat + delLat * i;
            timeData.push({
                geometry: {
                    type: 'Point',
                    coordinates: ol.proj.transform([pointNLng, pointNLat], 'EPSG:4326', 'EPSG:3857')
                },
                count: 1,
                time: i
            });
        }
    }

    // 构造数据
    $.ajax({
        url: '../data/qianxi-time',
        success: function (rs) {
            var items = rs.split('|');
            for (var i = 0; i < items.length; i++) {
                var itemArr = items[i].split(/\n/);
                for (var k = 0; k < itemArr.length; k++) {
                    if (!!itemArr[k]) {
                        var item = itemArr[k].split(/\t/);
                        if (item[0] === '起点城市' || item[0] === '迁出城市') {
                            var cityBegin = item[1];
                        }
                        if (item[0] !== '起点城市' || item[0] !== '迁出城市' && item.length > 1) {
                            var cityCenter1 = mapv.utilCityCenter.getCenterByCityName(item[0].replace(/市|省/, ""));
                            var cityCenter2 = mapv.utilCityCenter.getCenterByCityName(cityBegin.replace(/市|省/, "").trim());
                            if (cityCenter1) {
                                if (Math.random() > 0.7) {
                                    curive(cityCenter2, cityCenter1, 50);
                                }
                                data.push({
                                    geometry: {
                                        type: 'LineString',
                                        coordinates: [ol.proj.transform([cityCenter1.lng, cityCenter1.lat], 'EPSG:4326', 'EPSG:3857'), ol.proj.transform([cityCenter2.lng, cityCenter2.lat], 'EPSG:4326', 'EPSG:3857')]
                                    },
                                    count: 100 * Math.random()
                                });
                            }
                        }
                    }
                }
            }

            var dataSet = new mapv.DataSet(data);
            var mapvOptions = {
                strokeStyle: 'rgba(55, 50, 250, 0.3)',
                globalCompositeOperation: 'lighter',
                shadowColor: 'rgba(55, 50, 250, 0.5)',
                methods: {
                    click: function (item) {
                    }
                },
                gradient: {0: 'rgba(55, 50, 250, 0)', 1: 'rgba(55, 50, 250, 1)'},
                lineWidth: .2,
                draw: 'intensity'
            };

            var options = {
                map: map, dataSet: dataSet, mapvOptions: mapvOptions, attributions: ''
            };

            map.addLayer(new ol.layer.Image({
                source: new ol.source.Mapv(options)
            }));

            var dataSet = new mapv.DataSet(timeData);
            var mapvOptions = {
                fillStyle: 'rgba(255, 250, 250, 0.9)',
                size: .5,
                animation: {
                    type: 'time',
                    stepsRange: {
                        start: 0,
                        end: 50
                    },
                    trails: 1,
                    duration: 5,
                },
                draw: 'simple'
            };

            var options = {
                map: map, dataSet: dataSet, mapvOptions: mapvOptions
            };

            map.addLayer(new ol.layer.Image({
                source: new ol.source.Mapv(options)
            }));
        }
    });

</script>
</body>
</html>
